package com.cmuis.goodguide;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.util.Linkify;
import android.text.util.Linkify.TransformFilter;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

/*
 * This is the activity / page that will display information
 * about what the ratings signify. This page will mostly be
 * used when the user first downloads and uses the application.
 */
public class InfoPage extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.info_page);
		final TextView about_url = (TextView) findViewById(R.id.about_url);
		
		String txt = "View more information on GoodGuide";
		about_url.setText(txt);
		
		// pattern: pattern we want to match and turn into a clickable link
		Pattern pattern = Pattern.compile("View more information on GoodGuide");
		String scheme = "http://www.goodguide.com/about/ratings";
		//Turn it into a link
		TransformFilter transformFilter = new TransformFilter() {
				public final String transformUrl(final Matcher match, String url) 
				{ return ""; } }; 

		Linkify.addLinks(about_url, pattern, scheme,null, transformFilter);
	}

	// sets menu functionality
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.options_menu, menu);
		return true;
	}

	// Standard menu like all of the other activities / pages.
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.search:
			Intent j = new Intent(this, goodguide.class);
			startActivity(j);
			return true;
		case R.id.barcode_scanner:
			Intent i = new Intent(this, barcodescanner.class);
			startActivity(i);
			return true;
		case R.id.history:
			Intent p = new Intent(this, History.class);
			startActivity(p);
			return true;
		case R.id.info:
			Intent q = new Intent(this, InfoPage.class);
			startActivity(q);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
}